package com.example.lockfulldemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.example.lockfulldemo.entity.TicketEntity;
import com.example.lockfulldemo.mapper.TicketMapper;
import com.example.lockfulldemo.service.DemoService;
import com.example.lockfulldemo.tools.ThreadLocalUtil;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class DemoServiceImpl implements DemoService {
    public static TicketEntity ticketEntity = new TicketEntity();
    @Resource
    private TicketMapper ticketMapper;
    @Resource
    private ApplicationEventPublisher applicationEventPublisher;

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public void demo(){
        TicketEntity ticketEntity = ThreadLocalUtil.get();
        int i = 1;
        ticketMapper.update(null,new LambdaUpdateWrapper<TicketEntity>().set(TicketEntity::getNum,1));
        i = 2;
        applicationEventPublisher.publishEvent("1");
    }

    @Override
    public void demo1(){
        applicationEventPublisher.publishEvent(1);
    }
}
